# Object files to build - use '\' to split line before moving down to new line
define SOURCES
	arm_state.o \
	keypad_state.o \
	lcd_state.o \
	main.o \
	memory.o \
	state_loop.o
endef

# C compiler to use. Modify to point at either the cross compiler or gcc if 
# building on the board.
CC= gcc
# Program used for build control. make should be fine.
MK= make
# Flags to pass to the C compiler.
CFLAGS= -pipe -Wall -pedantic -O2 -Wfatal-errors
# Any libs to link in
LIBS= 
# Additional defines. Start each with -D
DEFINES= -D LINUX
# Leave blank. This should be set on the command line if used.
EXTRADEFINES= 

# Output directory relative to this file. Do not end with a '/'
OUTPUTDIR= bin
# Name of the executable to build
OUTPUTBIN= arm_controller
# Leave this - final build target.
OUTPUT= $(OUTPUTDIR)/$(OUTPUTBIN)

# Custom build rules exist for files with these extensions.
.SUFFIXES: .c

# Build the entire project.
all: 
	mkdir -p $(OUTPUTDIR)
	$(MK) $(OUTPUT) 

# Build the executable
$(OUTPUT): $(SOURCES)
	@echo Linking Object Files
	$(CC) $(CFLAGS) $(SOURCES) $(LIBS) -o $(OUTPUT) 

# Only tidy the built object files
clean_objs:
	rm -rf $(SOURCES)

# Tidy the build environment completely.
clean:
	rm -rf $(SOURCES) $(OUTPUT)
	rmdir $(OUTPUTDIR) 

info:
	@echo Building $(OUTPUT)
	$(CC) --version
	$(MK) --version

# Rule for building C files
.c.o:
	@echo Building $@ from $<
	$(CC) -c $(CFLAGS) $(DEFINES) $(EXTRADEFINES) -o $@ $<
